package ast;

public class CharacterConstant implements Expression {

	private char value;

	public CharacterConstant(String text) {
		if (isSimpleCharacter(text))
			value = text.charAt(2);
		else
			setNewLineOrSpace(text.charAt(2));
	}

	private boolean isSimpleCharacter(String text) {
		return text.length() == 3;
	}

	private void setNewLineOrSpace(char start) {
		value = Character.toLowerCase(start) == 'n' ? '\n' : ' ';
	}

	public char getValue() {
		return value;
	}

	@Override
	public void accept(Visitor visitor) {
		visitor.visitCharacterConstant(this);
	}

}
